import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    Dispatchplunder: "",
    NavClick: 1,
    userAddress: sessionStorage.getItem("account") || "",
    locale: localStorage.getItem("locale") || "en", // 从 localStorage 获取语言
    selectedWallet: null,
  },
  mutations: {
    setplunder(state, obj) {
      state.Dispatchplunder = obj;
    },
    setuserAddress(state, obj) {
      state.userAddress = obj;
    },
    setNavClick(state, index) {
      state.NavClick = index;
    },
    setLocale(state, locale) {
      state.locale = locale; // 更新语言
      localStorage.setItem("locale", locale); // 存储到 localStorage
    },
    setSelectedWallet(state, wallet) {
      state.selectedWallet = wallet;
    },
  },
  getters: {
    selectedWallet: (state) => state.selectedWallet,
  },
  actions: {
    changeLocale({ commit }, locale) {
      commit("setLocale", locale);
    },
  },
  modules: {},
});
